﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace ScreenSaverDigitalClock
{
    public partial class TimeScreenSaverWidget : UserControl
    {
        private int roleSize = 30;
        private int w = 0;
        private int h = 0;
        public TimeScreenSaverWidget()
        {
            InitializeComponent();
        }

        private void TimeScreenSaverWidget_Load(object sender, EventArgs e)
        {
            InitControls(30);
        }

        public void SetText(string txt)
        {
            labTxt.Text = txt;
            InitControls(roleSize);
        }

        public void SetFont(Font font)
        {
            labTxt.Font = font;
            InitControls(roleSize);
        }

        public void SizeWH(int w, int h)
        {
            this.w = w;
            this.h = h;
            InitControls(roleSize);
        }

        public void InitControls(int rs)
        {
            roleSize = rs;
            this.Width =  w == 0 ? (labTxt.Width + roleSize) : w;
            this.Height = h == 0 ? (labTxt.Height + roleSize) : h;
            roleTopLeft.Size = roleTopRight.Size = roleBottomLeft.Size = roleBottomRight.Size = new Size(roleSize, roleSize);
            roleTopLeft.Location =     new Point(0, 0);
            roleTopRight.Location =    new Point(this.Width - roleTopRight.Width, roleTopLeft.Location.Y);
            roleBottomLeft.Location =  new Point(roleTopLeft.Location.X, this.Height - roleBottomLeft.Height);
            roleBottomRight.Location = new Point(roleTopRight.Location.X, roleBottomLeft.Location.Y);

            bg1.Size = new Size(this.Width - roleSize, this.Height);
            bg2.Size = new Size(this.Width, this.Height - roleSize);
            bg1.Location = new Point(roleSize / 2, 0);
            bg2.Location = new Point(0, roleSize / 2);

            labTxt.Location = new Point((this.Width - labTxt.Width) / 2,(this.Height-labTxt.Height) / 2);
        }
    }
}
